package com.tianpengtech.admin.websitead;
import com.jfinal.aop.Before;
import com.jfinal.plugin.activerecord.Model;
import com.tianpengtech.admin.AbstractAdminController;
import com.tianpengtech.admin.InitInterceptor;
import com.tianpengtech.admin.dictionary.DictionaryDao;
import com.tianpengtech.common.exception.ValidateException;
import com.tianpengtech.common.model.dictionary.Dictionary;
import com.tianpengtech.common.model.websitead.WebSiteAd;

/**
* 路由配置地址：add("/admin/websitead", WebSiteAdAdminController.class, "/admin/websitead");
* 数据库映射地址：arp.addMapping(WebSiteAd.dao.tableName(),WebSiteAd.class);
*/
@Before(InitInterceptor.class)
public class WebSiteAdAdminController extends AbstractAdminController{

	@Override
	protected void config() {
		this.clazz=WebSiteAd.class;
		this.service=new WebSiteAdAdminServiceImpl();
	}

	@Override
	public void beforeAdd() {
		setAttr("objs",DictionaryDao.ME.readParents(Dictionary.WEBSITE_AD));
	}

	@Override
	public void beforeAdd(Model< ? > model) throws ValidateException {

	}

	@Override
	public void beforeQueryById(Model<?> model, int id) {
		setAttr("objs",DictionaryDao.ME.readParents(Dictionary.WEBSITE_AD));
	}

	@Override
	public void beforeUpdate(Model< ? > model) throws ValidateException {

	}

	@Override
	public void beforeDelete(Model< ? > model) {

	}
	
	/*
     * 列表页面
     */
    public void index() {
    	setAttr("objs",DictionaryDao.ME.readParents(Dictionary.WEBSITE_AD));
        renderTemplate(indexPage);
    }

	@Override
	public void parsePageRecord(Object results) {
	
		WebSiteAd ad = (WebSiteAd)results;
		Dictionary dic = DictionaryDao.ME.readDirecotryByCode(ad.getInt(WebSiteAd.CATEGORY));
		String name = dic.getStr(Dictionary.NAME);
		ad.set(WebSiteAd.CATEGORY, name);
	}
}

	